<include file="../Public/header_ajax" />
<!-- <p><?php dump($attach_id);?></p> -->
<form action="{:U('w3g/Index/ajax_image_upload')}" method="post" enctype="multipart/form-data">
		<input type="file" name="file" id="file" class="form-control" accept="image/gif,image.jpg,image/jpeg,image/pjpeg,image/png,image/bmp"/> 
	<div class="hide">
		<input type="text" name="attach_type" id="attach_type" value="feed_image"/>
		<input type="text" name="upload_type" id="upload_type" value="image"/>
		<eq name="channel" value="1">
			<input type="hidden" name="channel" value="1" />
		</eq>
        <button type="submit" name="submit" id="doupload" class="hide">上传</button>
	</div>
</form>
<div id="upload_alert_box">
	<div class="alert alert-success" id="upload_success"></div>
	<div class="alert alert-info" id="upload_info"></div>
	<div class="alert alert-warning" id="upload_warning"></div>
	<div class="alert alert-danger" id="upload_danger"></div>
</div>
<div id="loaded" class="hide">OK</div>
<?php 
$fileType=array("image/gif",
				"image/jpeg",
				"image/pjpeg",
				"image/png",
				"image/bmp"
			);
if(in_array($attach_type, $fileType)){
	$if_img='true';
	$src=getImageUrl($attach_src,100,100,true);
}else{
	$if_img='false';
	$src=getAttachUrl($attach_src);
}
 ?>
<script type="text/javascript">
fType=new Array('jpg','jpeg','png','bmp','gif');
$(function(){
	//类型判断
	var iconType='file';
	switch('<?php echo $attach_type;?>')
	{
		case 'application/pdf':
			iconType='pdf';
			break;
		case 'application/msword':
			iconType='word';
			break;
		case 'application/kswps':
			iconType='word';
			break;
		case 'application/vnd.ms-powerpoint':
			iconType='ppt';
			break;

	}
	// 获取父窗口分享类型记录
	var if_img=<?php echo $if_img;?>;
	var ischannel = "#ts-upload-img-box";
	<eq name="ischannel" value="1">
		ischannel = "#ts-upload-img-box_channel";
	</eq>
	if(if_img===true){
            window.parent.uploaded();
		$(window.parent.document).find('#post_twitter_input').data('type','image');
		$(window.parent.document).find(ischannel).prepend('<div class="file_list_view" style="background-image:url(<?php echo $src;?>);" data-id="<?php echo $attach_id;?>"><i class="ts-listen" data-listen="weibo-delimage-true">&times;</i></div>');
		$(window.parent.document).find('.file_list_view_del').remove();
//		window.parent.tiph();
	}else{
            window.parent.uploaded();
            window.parent.$.ui.showMask('<?php echo $return["data"];?>',true);
	}
	/*if($(window.parent.document).find('#post_twitter_input').data('type')===undefined){
		if(if_img){
			$(window.parent.document).find('#post_twitter_input').data('type','image');
			$(window.parent.document).find('#file_list').append('<div class="file_list_view" style="background-image:url(<?php echo $src;?>);" data-id="<?php echo $attach_id;?>"></div>');
		}else{
			$(window.parent.document).find('#post_twitter_input').data('type','file');
			$(window.parent.document).find('#file_list').append('<div class="file_list_view file_list_view_'+iconType+'" data-id="<?php echo $attach_id;?>"></div>');
		}
	}else if($(window.parent.document).find('#post_twitter_input').data('type')==='image' ){
		if(if_img===false){
			$(window.parent.document).find('#post_twitter_input').data('type','file');
			$(window.parent.document).find('#file_list').append('<div class="file_list_view file_list_view_'+iconType+'" data-id="<?php echo $attach_id;?>"></div>');
		}else{
			$(window.parent.document).find('#file_list').append('<div class="file_list_view" style="background-image:url(<?php echo $src;?>);" data-id="<?php echo $attach_id;?>"></div>');
		}
	}else{
		if(if_img===true){
			$(window.parent.document).find('#file_list').append('<div class="file_list_view" style="background-image:url(<?php echo $src;?>);" data-id="<?php echo $attach_id;?>"></div>');
		}else{
			$(window.parent.document).find('#file_list').append('<div class="file_list_view file_list_view_'+iconType+'" data-id="<?php echo $attach_id;?>"></div>');
		}
	}*/
	//上传动作
	if($(window.parent.document).find('#post_twitter_input').data('attach_id')===undefined){
		$(window.parent.document).find('#post_twitter_input').data('attach_id','|<?php echo $attach_id;?>|');
	}else{
		$(window.parent.document).find('#post_twitter_input').data('attach_id',$(window.parent.document).find('#post_twitter_input').data('attach_id')+'<?php echo $attach_id;?>|');
	}
	$(document).on('change','#file',function(){
                window.parent.uploading();
		$('#doupload').trigger('click');
//		window.parent.tips('上传中...',2,0);
	});
});
</script>
</body>
</html>